﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace WareHouseManagement.Common
{
    public  class GlobalValues
    {
        /// <summary>
        /// 用于等程序关闭时候把线程关闭掉
        /// </summary>
        public static bool isClosing = false;
        /// <summary>
        /// 等待一百毫秒
        /// </summary>
        public static readonly int minWaitTime = 100;
        public static readonly int maxWaitTime = 500;
        public static readonly int maxmaxWaitTime = 1000;
        public static readonly int maxmaxmaxWaitTime = 10000;

        public static string ManageName = "Admin";

        public static string ManagePassword = "Admin@123";
        /// <summary>
        /// 登录用户的信息
        /// </summary>
        //public static UserInfoEntity UserInfo { get; set; }
        //public static RollEntity RollEntity { get; set; }
        ///// <summary>
        ///// 配置文件中的信息
        ///// </summary>
        //private static SettingPara settingPara ;

        //public static SettingPara GetSettingPara()
        //{
        //    return settingPara ?? (settingPara = SettingPara.LoadSetting());
        //}

        //public static ObservableCollectionFast<Val_Des> Rolls { get; set; } = new ObservableCollectionFast<Val_Des>();
        public static ObservableCollection<Val_Des> States { get; set; } = GetVal_Dess<State>();
        public static ObservableCollection<Val_Des> TaskStates { get; set; } = GetVal_Dess<TaskState>();
        public static ObservableCollection<Val_Des> MaterialStates { get; set; } = GetVal_Dess<MaterialState>();
        public static ObservableCollection<Val_Des> Rows { get; set; } = GetVal_Dess<Rows>();
        public static ObservableCollection<Val_Des> TaskTypes { get; set; } = GetVal_Dess<TaskType>();

        public static ObservableCollection<Val_Des> BakingStates { get; set; } = new ObservableCollection<Val_Des>();
        public static ObservableCollection<Val_Des> GetVal_Dess<T>()
        {
            ObservableCollection<Val_Des> EnumModelList = new ObservableCollection<Val_Des>();
            Array array = Enum.GetValues(typeof(T));
            foreach (var item in array)
            {//通过遍历枚举拿到遍历的枚举值，然后根据枚举值拿到对应的枚举名称 在添加到list集合里 就Ok 很实在的方法 而且还很简单
                Val_Des EnumModel = new Val_Des();
                EnumModel.ID = Convert.ToInt32(item);
                EnumModel.Val = Convert.ToInt32(item);
                EnumModel.Description = GetEnumDescription((T)item);
                if (EnumModel.Description == ((T)item).ToString()) continue;
                EnumModelList.Add(EnumModel);
            }
            return EnumModelList;
        }
        public static string GetEnumDescription<T>(T enumValue)
        {
            string value = enumValue.ToString();
            FieldInfo field = enumValue.GetType().GetField(value);
            object[] objs = field.GetCustomAttributes(typeof(DescriptionAttribute), false);  //获取描述属性
            if (objs == null || objs.Length == 0)  //当描述属性没有时，直接返回名称
                return value;
            DescriptionAttribute descriptionAttribute = (DescriptionAttribute)objs[0];
            return descriptionAttribute.Description;
        }
        static GlobalValues()
        {
            BakingStates  = GetVal_Dess<Bakingstate>();
        }
    }
    public enum Rows : int
    {
        [Description("单排")]
        Singlerow = 0,
        [Description("第一排（不靠近通道侧）")]
        Firstrow = 1,
        [Description("第二排（靠近通道侧）")]
        Secondrow = 2
    }
    /// <summary>
    /// 物料种类 0空，1有物料，2空载具
    /// </summary>
    public enum MaterialState : int
    {
        [Description("空")]
        Empty = 0,
        [Description("有物料")]
        Material = 1,
        [Description("空工装")]
        Emptytooling = 2,
    }
    public enum State : int
    {
        [Description("未占用")]
        Unoccupied = 0,
        [Description("待运出")]
        Tobeshippedout,
        [Description("待运达")]
        Tobetransported,
        [Description("人为锁定")]
        locking
    }
    public enum Bakingstate:int
    {

        [Description("未知状态")]
        unknow = 1,
        [Description("无需烘烤")]
        Nobaking,
        [Description("已经烘烤")]
        Baked,
        [Description("待烘烤")]
        Tobebaked,
    }
    public enum TaskState : int
    {
        [Description("未执行")]
        unexecuted = 0,
        [Description("已下发")]
        Issued,
        [Description("执行中")]
        execution,
        [Description("取料完成")]
        Reclaimingcompleted,
        [Description("送料中")]
        feeding,
        [Description("送料完成")]
        Feedingcompleted,
        [Description("取料异常")]
        Reclaimingabnormal,
        [Description("送料异常")]
        Feedingabnormal



        //  0无含义，1承接任务中，2取料完成，3送料中，4送料完成，5取料异常，6送料异常。

    }

    public enum TaskType : int
    {
        [Description("转运满料")]
        TransferFull = 1,
        [Description("转运空工装")]
        TransferEmpty = 2,
    }
    public class Val_Des
    {
        public int ID { get; set; }
        public int Val { get; set; }
        public string Description { get; set; }

    }
}
